package com.framwork.core.api.accessToken.input;

import com.alibaba.fastjson.JSONObject;
import com.framwork.core.base.AbstractAPIInput;
import okhttp3.FormBody;
import okhttp3.RequestBody;

import java.util.Objects;

/**
 * @author ：james.liu
 * @date ：Created in 2022/3/4 15:48
 * @description：获取 app_access_token（应用商店应用）
 * @version: 1.0
 */
public class OpenApisAuthV3AppAccessTokenInput extends AbstractAPIInput {

    private String appId;

    private String appSecret;

    private String appTicket;

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }

    public String getAppTicket() {
        return appTicket;
    }

    public void setAppTicket(String appTicket) {
        this.appTicket = appTicket;
    }

    public final RequestBody toRequestBody() {
        RequestBody r = null;
        final FormBody.Builder builder = new FormBody.Builder();
        builder.add("app_id", this.getAppId());
        builder.add("app_secret", this.getAppSecret());
        builder.add("app_ticket", this.getAppTicket());
        r = builder.build();
        return r;
    }

    public final RequestBody toRequestBody(OpenApisAuthV3AppAccessTokenInput input) {
        if (Objects.isNull(input)) {
            return null;
        }
        RequestBody r = null;
        final FormBody.Builder builder = new FormBody.Builder();
        builder.add("app_id", input.getAppId());
        builder.add("app_secret", input.getAppSecret());
        builder.add("app_ticket", input.getAppTicket());
        r = builder.build();
        return r;
    }

    public final String toBody(OpenApisAuthV3AppAccessTokenInput input) {
        if (Objects.isNull(input)) {
            return null;
        }
        JSONObject r = new JSONObject();
        r.put("app_id", input.getAppId());
        r.put("app_secret", input.getAppSecret());
        r.put("app_ticket", input.getAppTicket());
        return r.toJSONString();
    }
}
